Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
Unable to find an element with the placeholder text "Search..." reactjs jest

I have a component that uses async and await.

I am trying to test whether the placeholder for the input renders.

However, I always get the above error.

This is component:

const [Loading, setLoading] = useState(false)
const [name, setName] = useState('');
const [options, setOptions] = useState([])
const [data, setData] = useState(false)

useEffect(() => {
  setLoading(true)
  const newUsers = async() => {
    const response = await fetch('https://jsonplaceholder.typicode.com/users')
      .then((res) => res.json())
      .then((data) => {
        setData(data)
      });

  };
  newUsers();
}, [])

if (!data) return <p className = 'text-center font-bold text-6xl' > Loading... < /p>
if (!Loading) return <p className = 'text-center font-bold text-6xl' > Data loaded < /p>

<input id = "input"
className = 'w-96  h-16 border-1 shadow-lg rounded-lg'
placeholder = "Search..."

onChange = {
  e => handleChange(e.target.value)
}
value = {
  name
}
/>
   

This is the test

test('input appears', async () => {
    await waitFor(() => {
        expect(screen.getByPlaceholderText('Search...')).toBeInTheDocument()
      })
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Looks like you forgot to return the input

const [Loading, setLoading] = useState(false)
const [name, setName] = useState('');
const [options, setOptions] = useState([])
const [data, setData] = useState(false)

useEffect(() => {
  setLoading(true)
  const newUsers = async() => {
    const response = await fetch('https://jsonplaceholder.typicode.com/users')
      .then((res) => res.json())
      .then((data) => {
        setData(data)
      });

  };
  newUsers();
}, [])

if (!data) return <p className = 'text-center font-bold text-6xl' > Loading... < /p>
if (!Loading) return <p className = 'text-center font-bold text-6xl' > Data loaded < /p>

return (    // <---- Return
  <input id = "input"
    className = 'w-96  h-16 border-1 shadow-lg rounded-lg'
    placeholder = "Search..."

    onChange = {
     e => handleChange(e.target.value)
    }
    value = {
     name
    }
  />
);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda